package Parking;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PFrame extends JFrame{

	public PFrame() {
		intPFrame();
		this.setVisible(true);
	}
	
	public   void  intPFrame() {
		CarApplication capp=new CarApplication();
		GridLayout  layout=new GridLayout(2,2);
	    layout.setHgap(40);
	    layout.setVgap(40);
	   
	    JPanel panel =new JPanel(layout); 
	    JButton Jbt1=new JButton("车辆入库");
	    JButton Jbt2=new JButton("车辆出库");
	    JButton Jbt3=new JButton("查询车辆");
	    JButton Jbt4=new JButton("退出系统");
	    Jbt1.addActionListener(new action() {
	    @Override
	    public void actionPerformed(ActionEvent e) {
	    	
			JFrame  frame=new JFrame();//新开一个窗口
			JPanel  jp=new JPanel();//新开一个容器，放在窗口里
			JTextField  textfield=new JTextField();//文本表格，用于用户输入
			textfield.setEditable(true);//设为可编辑
			textfield.setColumns(11);//设定可输入长度
			JLabel jl=new JLabel("车牌号码");//设置提示信息
			jp.add(jl);
			jp.add(textfield);
			JButton  jtb=new JButton("确定");
			jtb.addActionListener( new  action() {//动作监听
				@Override
				public void actionPerformed(ActionEvent e) {
					frame.dispose();//将第一个窗口关闭
					String  carcard=textfield.getText();//收集终端输入的信息
					String  str=null;
					if(carcard.isEmpty()) {//判断用户是否输入车牌号
						 str="当前未输入车牌号，请输入你想查找的车牌号";
					}
					else{
						  str=capp.getin(carcard);
					}
				    JFrame  frame1=new JFrame();//再开一窗口，用于显示入库信息
				    JPanel  jp1=new JPanel();
				    JLabel jla=new JLabel(str);
			   	    jp1.add(jla);
			   	    jla.setBounds(200, 150, 60, 60);
		     		frame1.add(jp1);
		     		frame1.setTitle("入库状态");
					frame1.setSize(750,250);
					frame1.setLocationRelativeTo(null);
					frame1.setVisible(true);
				}
			});
			jp.add(jtb);
		
			frame.add(jp);
			frame.setTitle("车辆入库");
			frame.setSize(250,300);
			frame.setLocationRelativeTo(null);
			frame.setVisible(true);
			
	    }});
	    Jbt2.addActionListener(new action() {
		    @Override
		    public void actionPerformed(ActionEvent e) {
		    	
				JFrame  frame=new JFrame();
				frame.setTitle("车辆出库");
				JPanel  jp=new JPanel();
				JTextField  textfield=new JTextField();
				textfield.setEditable(true);
				textfield.setColumns(11);
				JLabel jl=new JLabel("车牌号码");
				jp.add(jl);
				jp.add(textfield);
				JButton  jtb=new JButton("确定");
				jtb.addActionListener( new  action() {
					@Override
					public void actionPerformed(ActionEvent e) {
						frame.dispose();
						String  carcard=textfield.getText();
						String  str=null;
						if(carcard.isEmpty()) {
							 str="当前未输入车牌号，请输入你想查找的车牌号";
						}
						else{
							  str=capp.getout(carcard);
						}
						
					    JFrame  frame1=new JFrame();
					    JPanel  jp1=new JPanel();
					    JLabel jla=new JLabel(str);
				   	   jp1.add(jla);
			     		frame1.add(jp1);
			     		frame1.setTitle("出库状态");
						frame1.setSize(1000,250);
						frame1.setLocationRelativeTo(null);
						frame1.setVisible(true);
					}
				});
				jp.add(jtb);
			
				frame.add(jp);
				frame.setSize(250,300);
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
				
		    }});
	    Jbt3.addActionListener(new action() {
		    @Override
		    public void actionPerformed(ActionEvent e) {
		    	
				JFrame  frame=new JFrame();
				frame.setTitle("查询车辆");
				JPanel  jp=new JPanel();
				JTextField  textfield=new JTextField();
				textfield.setEditable(true);
				textfield.setColumns(11);
				JLabel jl=new JLabel("车牌号码");
				jp.add(jl);
				jp.add(textfield);
				JButton  jtb=new JButton("确定");
				jtb.addActionListener( new  action() {
					@Override
					public void actionPerformed(ActionEvent e) {
						frame.dispose();
						String  carcard=textfield.getText();
						String  str=null;
						if(carcard.isEmpty()) {
							 str="当前未输入车牌号，请输入你想查找的车牌号";
						}
						else{
							  str=capp.Findcar(carcard);
						}
						
											
					    JFrame  frame1=new JFrame();
					    JPanel  jp1=new JPanel();
					    JLabel jla=new JLabel(str);
					    
				   	    jp1.add(jla);
				   	    
			     		frame1.add(jp1);
			     		frame1.setTitle("查询状态");
						frame1.setSize(1000,250);
						frame1.setLocationRelativeTo(null);
						frame1.setVisible(true);
					}
				});
				jp.add(jtb);
			   frame.add(jp);
				frame.setSize(250,300);
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
				
		    }});
	    Jbt4.addActionListener(new action() {
		    @Override
		    public void actionPerformed(ActionEvent e) {
		    	System.exit(0);
				
		    }});
	
	    panel.add(Jbt1);
	    panel.add(Jbt2);
	    panel.add(Jbt3);
	    panel.add(Jbt4);
	    this.setContentPane(panel);
		this.setSize(788, 630);
		this.setTitle("停车场管理系统");
		this.setBackground(getForeground());;
    	//this.setAlwaysOnTop(true);
    	this.setLocationRelativeTo(null);
    	this.setDefaultCloseOperation(3);
    	
	
	}
	
	
	
	
	
	
	
	
	
}
